package com.lin.sqltool.utils;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class IconUtil {

    private static final Map<String, Image> iconCache = new HashMap<>();

    public static ImageView createIcon(String iconPath, double width, double height) {
        Image iconImage = iconCache.get(iconPath);
        if (iconImage == null) {
            iconImage = new Image(Objects.requireNonNull(IconUtil.class.getResourceAsStream(iconPath)));
            iconCache.put(iconPath, iconImage);
        }
        ImageView icon = new ImageView(iconImage);
        icon.setFitWidth(width);
        icon.setFitHeight(height);
        return icon;
    }




}
